home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / Window.C < prev    next >
C/C++ Source or Header  |  1992-08-24  |  6KB  |  350 lines

  1. #ifdef __GNUG__
  2. #pragma implementation
  3. #endif
  4.  
  5. #include "Window.h"
  6.  
  7. #include "Class.h"
  8. #include "Error.h"
  9. #include "WindowPort.h"
  10. #include "WindowSystem.h"
  11. #include "ObjectTable.h"
  12. #include "ClassManager.h"
  13. #include "Storage.h"
  14. #include "View.h"
  15. #include "Document.h"
  16. #include "Env.h"
  17. #include "Look.h"
  18. #include "Buttons.h"
  19. #include "String.h"
  20.  
  21. #include "MenuBar.h"
  22.  
  23. extern bool testwindow;
  24. extern char *gProgPath;
  25.  
  26. Token gToken;
  27. Window *gWindow;
  28.  
  29. //---- Window ----------------------------------------------------------------
  30.  
  31. NewMetaImpl(Window,Clipper, (TB(active), TP(manager), TP(portDesc), TP(icon)));
  32.  
  33. Window::Window(Manager *m, Point e, WindowFlags f, VObject *in, char *title)
  34.                             : Clipper(0, gPoint_1)
  35. {
  36.     Init(m, in, eWinStandard, eCrsBoldArrow, f, title, e);
  37. }
  38.     
  39. Window::Window(Manager *m, VObject *vp, WindowType wt, WindowFlags f, Point e,
  40.     char *title)
  41.                             : Clipper(0, gPoint_1)
  42. {
  43.     Init(m, vp, wt, eCrsBoldArrow, f, title, e);
  44. }
  45.  
  46. void Window::Init(Manager *eh, VObject *in, WindowType wt, GrCursor curs,
  47.                         WindowFlags wf, char *t, Point e)
  48. {
  49.     wtype= wt;
  50.     wflags= wf;
  51.     manager= eh;
  52.     ResetFlag(eVObjOpen);
  53.     cursor= curs;
  54.     bgcolor= gInkNone;
  55.     bgcolor= gLook->GetBackgroundColor();
  56.     SetDeleteVop(TRUE);
  57.     inner= in;
  58.     contentRect.extent= e;
  59.     VObject *v= gWindowSystem->MakeWindowBorder(wtype, inner, t, wf & eWinBlock, wf & eWinFixed);
  60.     Add(v);
  61. }
  62.  
  63. Window::~Window()
  64. {
  65.     if (vop != inner) {
  66.     if (deleteVop)
  67.         SafeDelete(inner);
  68.     deleteVop= TRUE;
  69.     }
  70.     if (icon) {
  71.     Window *tmp= icon;
  72.     icon= 0;
  73.     delete tmp;
  74.     }
  75.     if (portDesc) {
  76.     portDesc->Remove();     // mark as free
  77.     portDesc= 0;
  78.     }
  79. }
  80.  
  81. void Window::ExtentChanged(VObject*)
  82. {
  83.     // SetExtent(Max(GetMinSize().Extent(), GetExtent()));
  84.     SetExtent(GetMinSize().Extent());
  85. }
  86.  
  87. Command *Window::DoMenuCommand(int cmd)
  88. {
  89.     return Clipper::DoMenuCommand(cmd);
  90. }
  91.  
  92. EvtHandler *Window::GetNextHandler()
  93. {
  94.     return manager;
  95. }
  96.  
  97. void Window::SetNextManager(Manager *m)
  98. {
  99.     manager= m;
  100. }
  101.  
  102. void Window::InvalidateRect(Rectangle r)
  103. {
  104.     MakePort()->InvalidateRect(r);
  105. }
  106.  
  107. void Window::SetExtent(Point e)
  108. {
  109.     MakePort()->SetExtent(e);
  110. }
  111.  
  112. void Window::SetOrigin(Point at)
  113. {
  114.     VObject::SetOrigin(gPoint0);
  115.     MakePort()->SetOrigin(GetRect().origin+at);
  116. }
  117.  
  118. void Window::Focus()
  119. {
  120.     if (IsOpen() && portDesc) {
  121.     GrSetPort(portDesc);
  122.     GrInitClip();
  123.     GrClipFurther(contentRect);
  124.     GrTranslate(Offset());
  125.     }
  126. }
  127.  
  128. void Window::FocusNotify(bool f)
  129. {
  130.     gWindow= this;
  131.     if (portDesc == 0)
  132.     return;
  133.     GrSetPort(portDesc);
  134.     if (active != f) {
  135.         active= f;
  136.         if (manager)
  137.         manager->SetActive(active);
  138.     }
  139. }
  140.  
  141. void Window::InputNotify(Token *t)
  142. {
  143.     gWindow= this;
  144.     if (portDesc == 0)
  145.     return;
  146.     GrSetPort(portDesc);
  147.     
  148.     gToken= *t;
  149.     
  150.     if (t->Code == eEvtEnter || t->Code == eEvtExit) {
  151.         bool f= t->Code == eEvtEnter;
  152.         if (f != active) {
  153.         active= f;
  154.         if (manager)
  155.             manager->SetActive(active);
  156.     }
  157.     } else if (t->IsKey() && t->Flags == (eFlgShiftKey|eFlgCntlKey|eFlgMetaKey)) {
  158.     switch (t->MapToAscii()) {
  159.     case 'q':           // emergency exit
  160.         Close();
  161.         break;
  162.     case 't':
  163.         gSystem->Abort();
  164.         break;
  165.     case 'p':
  166.         Print();
  167.         break;
  168.     case 's':
  169.         gClassManager->InstanceStatistics();
  170.         break;
  171.     case 'i':
  172.         gClassManager->InstanceStatistics(TRUE);
  173.         break;
  174.     case 'l':
  175.         ToggleLook();
  176.         {
  177.         vop->SetExtent(GetExtent());
  178.         vop->SetOrigin(gPoint0);
  179.         ForceRedraw();
  180.         UpdateEvent();
  181.         }
  182.         break;
  183.     case 'e':
  184.         Error("InputNotify", "forced invocation of ErrorHandler");
  185.         break;
  186.     case 'm':
  187.         Storage::Statistics();
  188.         break;
  189.     }
  190.     return;
  191.     }
  192.     
  193.     if (manager && (gToken.IsKey() || gToken.IsFunctionKey() || gToken.IsCursorKey())) {
  194.     manager->InputKbd(gToken);
  195.     } else {
  196.     PerformCommand(DispatchEvents(gToken.Pos, gToken, this));
  197.     }
  198.     UpdateEvent();
  199. }
  200.  
  201. void Window::OpenNotify(Point e)
  202. {
  203.     if (testwindow) fprintf(stderr, "OpenNotify: %d %d\n", e.x, e.y);
  204.     if (portDesc) {
  205.     gWindow= this;
  206.     GrSetPort(portDesc);
  207.     if (! IsOpen())
  208.         Clipper::Open(TRUE);
  209.     VObject::SetExtent(e);
  210.     if (vop)
  211.         vop->SetContentRect(Rectangle(gPoint0, e), TRUE);
  212.     UpdateEvent();
  213.     }
  214. }
  215.  
  216. void Window::CloseNotify()
  217. {
  218.     if (IsOpen()) {
  219.     if (testwindow) fprintf(stderr, "CloseNotify\n");
  220.     Clipper::Open(FALSE);
  221.     }
  222. }
  223.  
  224. void Window::ResizeNotify(Point e)
  225. {
  226.     if (IsOpen())
  227.     if (testwindow) fprintf(stderr, "ResizeNotify: %d %d\n", e.x, e.y);
  228. }
  229.  
  230. GrCursor Window::GetCursor(Point)
  231. {
  232.     return cursor;
  233. }
  234.  
  235. class WindowPort *Window::MakePort()
  236. {
  237.     if (portDesc == 0)
  238.     portDesc= gWindowSystem->MakeWindow(this, wtype, cursor);
  239.     return portDesc;
  240. }
  241.  
  242. void Window::Open(bool mode)
  243. {
  244.     if (mode)   // open
  245.     OpenAt(GetRect().origin);
  246.     else if (portDesc)
  247.     portDesc->Hide();
  248. }
  249.  
  250. void Window::OpenAt(Point p, VObject *fp, bool resize, bool block)
  251. {
  252.     WindowPort *fatherport= 0;
  253.     
  254.     if (IsOpen()) {
  255.     Top();
  256.     return;
  257.     }
  258.     if (fp) {
  259.     Window *w= fp->GetWindow();
  260.     if (w)
  261.         fatherport= (WindowPort*) (w->portDesc);   
  262.     p= fp->GetPortPoint(p);
  263.     }
  264.  
  265.     GrSetPort(MakePort());
  266.  
  267.     if (resize)
  268.     contentRect= gPoint0;
  269.  
  270.     Point e= Max(GetMinSize().Extent(), GetExtent());
  271.     if (manager)
  272.     p-= manager->GetInitialPos(e);
  273.     
  274.     portDesc->Show(fatherport, Rectangle(p, e), block || (wflags & eWinBlock));
  275.  
  276.     if (fatherport)
  277.     GrSetPort(fatherport);
  278. }
  279.  
  280. void Window::Iconize()
  281. {
  282.     if (icon == 0)
  283.     icon= MakeIcon();
  284.     if (icon)
  285.     icon->icon= this;
  286.     MakePort()->Iconize();
  287. }
  288.  
  289. Window *Window::MakeIcon()
  290. {
  291.     if (manager) {
  292.     VObject *vop= manager->DoMakeIconContent();
  293.     char *label= BaseName(gProgPath);
  294.     if (vop)
  295.         return new Window(manager, vop, eWinIcon, eWinFixed, Point(64), label);
  296.     }
  297.     return 0;
  298. }
  299.  
  300. Rectangle Window::ScreenRect()
  301. {
  302.     return WindowSystem::screenRect - GetRect().origin;
  303. }
  304.  
  305. void Window::ReadEvent(Token &t, int timeout, bool overread)
  306. {
  307.     MakePort()->GetEvent(&gToken, timeout, overread);
  308.     t= gToken;
  309. }
  310.  
  311. Rectangle Window::GetRect()
  312. {
  313.     return MakePort()->GetRect();
  314. }
  315.  
  316. void Window::PushBackEvent(Token t)
  317. {
  318.     MakePort()->PushEvent(t);
  319. }
  320.  
  321. void Window::Top()
  322. {
  323.     MakePort()->Top();
  324. }
  325.  
  326. void Window::Bottom()
  327. {
  328.     MakePort()->Bottom();
  329. }
  330.  
  331. void Window::Bell(long d)
  332. {
  333.     MakePort()->Bell(d);
  334. }
  335.  
  336. void Window::SetMousePos(Point p)
  337. {
  338.     MakePort()->SetMousePos(p);
  339. }
  340.  
  341. void Window::Grab(bool g, bool fs)
  342. {
  343.     MakePort()->Grab(g, fs);
  344. }
  345.  
  346. void Window::SetTitle(char *tit)
  347. {
  348.     MakePort()->SetTitle(tit);
  349. }
  350.